﻿using System;
using NguyenHoa.Web.App_Code;
using NguyenHoa.Services;

namespace NguyenHoa.Web.Controls
{
  public partial class NewsLetter : BaseControl
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void cbFooter_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
      string para = e.Parameter;
      if (para == "NewsLetterRegistery")
      {
        e.Result = SaveNewsLetter();
      }
    }

    private string SaveNewsLetter()
    {
      try
      {
        NewsLetterService service = new NewsLetterService();
        Domains.NewsLetter newsletter = service.GetByEmail(Utils.SafeString(txtEmail.Text));
        if (newsletter != null)
        {
          return Resources.Messages.ERR0026;
        }
        newsletter = new Domains.NewsLetter();
        newsletter.Email = Utils.SafeString(txtEmail.Text);
        service.Insert(newsletter);
      }
      catch (Exception ex)
      {
        WriteLog("Footer::SaveNewsLetter", ex);
        return Resources.Messages.ERR0004;
      }
      return string.Empty;
    }
  }
}